package com.ruoyi.kenuo.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.kenuo.domain.KernelChina;
import com.ruoyi.kenuo.service.IKernelChinaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 省市区Controller
 *
 * @author polo
 * @date 2022-11-01
 */
@Api(tags="省市区联动相关接口")
@RestController
@RequestMapping("/kenuo/china")
public class KernelChinaController extends BaseController
{
    @Autowired
    private IKernelChinaService kernelChinaService;

    /**
     * 查询省市区列表
     */
    @ApiOperation(value="查询省市区列表", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pid", value = "pid父级id", required = true, dataType = "String")
    })
    @PreAuthorize("@ss.hasPermi('kenuo:china:list')")
    @GetMapping("/list")
    public AjaxResult list(KernelChina kernelChina)
    {
        List<KernelChina> list = kernelChinaService.selectKernelChinaList(kernelChina);
        return AjaxResult.success(list);
    }

    /**
     * 导出省市区列表
     */
    @PreAuthorize("@ss.hasPermi('kenuo:china:export')")
    @Log(title = "省市区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KernelChina kernelChina)
    {
        List<KernelChina> list = kernelChinaService.selectKernelChinaList(kernelChina);
        ExcelUtil<KernelChina> util = new ExcelUtil<KernelChina>(KernelChina.class);
        util.exportExcel(response, list, "省市区数据");
    }

    /**
     * 获取省市区详细信息
     */
    @PreAuthorize("@ss.hasPermi('kenuo:china:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(kernelChinaService.selectKernelChinaById(id));
    }

    /**
     * 新增省市区
     */
    @PreAuthorize("@ss.hasPermi('kenuo:china:add')")
    @Log(title = "省市区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KernelChina kernelChina)
    {
        return toAjax(kernelChinaService.insertKernelChina(kernelChina));
    }

    /**
     * 修改省市区
     */
    @PreAuthorize("@ss.hasPermi('kenuo:china:edit')")
    @Log(title = "省市区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KernelChina kernelChina)
    {
        return toAjax(kernelChinaService.updateKernelChina(kernelChina));
    }

    /**
     * 删除省市区
     */
    @PreAuthorize("@ss.hasPermi('kenuo:china:remove')")
    @Log(title = "省市区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(kernelChinaService.deleteKernelChinaByIds(ids));
    }
}
